<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.lsms.dao.impl.*" %>
<%@ page import="org.lsms.bean.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>Chair Paper Assign Details Page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="LSMS,ICSEE,CHAIR">
	
	<link rel="stylesheet" type="text/css" href="../css/author_layout.css">
	<link rel="stylesheet" type="text/css" href="../css/hyper_link_style.css">

	<script type="text/javascript">
	
	function openpage(curpage)
	{
		document.spage.page.value = curpage ;		
		document.spage.submit() ;
	}
	
	function a_openpage(a_curpage)
	{
		document.a_spage.a_page.value = a_curpage ;		
		document.a_spage.submit() ;
	}
	
	function check(member_id)
	{
		var a = window.confirm("Are you sure you want to assign this paper to member "+member_id+"?");
		if(a){
			return true;
		}else{
			return false;
		}
	}
	
	function check_all(member_id)
	{
		var s = "";
		var i = 0;
		var length = document.assign_paper.assignment.length;
		for(i=0;i<length;i++)
		{
			if(document.assign_paper.assignment[i].checked)
			{
				s = s+document.assign_paper.assignment[i].value+",";
			}
		}
		
		if(s!=""){
			var a = window.confirm("Are you sure you want to assign paper "+s+" to member "+member_id+"?" )
			if(a){
				window.location = "../paper_assign1_all?member_id="+member_id+"&paper_id="+s;
				
			}else{
				return false;
			}
		}
		else{
			alert("Please select at least one paper!");
			return false;
		}
	}
	
	function get_paper_id(member_id)
	{
		var s = "";
		var i = 0;
		for(i=0;i<document.assign_paper.assignment.length;i++)
		{
			if(document.assign_paper.assignment[i].checked)
			{
				s = s+document.assign_paper.assignment[i].value+"+";
			}
		}
		return s;
	}
	
	
	function select_all()
	{
    	var a = document.getElementsByTagName("input");
   		if(a[0].checked==true){
   		for (var i=0; i<a.length; i++)
      		if (a[i].type == "checkbox") a[i].checked = false;
   		}
   		else
   		{
  		 for (var i=0; i<a.length; i++)
      		if (a[i].type == "checkbox") a[i].checked = true;
   		}
	}
	
	function selectall()
	{
    	
    	var b = document.getElementsByName("select_all");
   		if(b[0].checked==true){
   		var ass = document.getElementsByName("assignment");
   		for (var i=0; i<ass.length; i++)
      		ass[i].checked = true;
   		}
   		else
   		{
   		var ass = document.getElementsByName("assignment");
  		 for (var i=0; i<ass.length; i++)
      		ass[i].checked = false;
   		}
	}
	
	</script>

  </head>
  
  <body>
	<div id="container">
		<div id="header" class="logo_image"></div>
		<div class="nav"></div>
		<div id="author_menu" class="border">
			<table border="0" width="100%"  >
				<tr>
					<td  bgcolor="#CCCCCC"><a href="../index.jsp">Home</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="chair_decision.jsp">View All Papers/Decision</a></td>
				</tr>
				<tr>
				<%
					DaoImpl impl = new DaoImpl();
					HashMap<String,Integer> hm = impl.get_site_setting();
					int member_invite = hm.get("member_invite");
					if(member_invite==1){
				 %>
					<td  bgcolor="#CCCCCC"><a href="invite_member.jsp">Invite PC Member</a></td>
				<%
					}else{
				 %>
				 	<td  bgcolor="#CCCCCC"><a href="../error/invite_member_forbidden.jsp">Invite PC Member</a></td>	
				<%
					}
				 %>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="member_conf.jsp">Pcmember Confirmation</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="paper_assign.jsp">Paper Assign</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="assign_index.jsp">Assign Papers' Indexes</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="modify_info.jsp">Modify Information</a></td>
				</tr>
				<tr>
					<td  bgcolor="#CCCCCC"><a href="../logout">Log Out</a></td>
				</tr>
			</table>
		</div>
		
		<div id="content" class="bg_color border" >
		<div style="margin:15px">
			<%
				int member_id =Integer.parseInt(request.getParameter("id"));
				User user = impl.get_user_info(member_id);
			 %>
			<br>
			<b>Paper Distribution</b>
			
			<p style="text-align:left">PC Member Info</p>
			<div id="member_info" class="border" style="height:100px">
			<table align="center" border="0" style="width:600px">
			<tr>
				<td><b>Login Name</b></td>
				<td><% out.print(user.getLoginname());%></td>
				<td><b>Address</b></td>
				<td><% out.print(user.getAddress()); %></td>
			</tr>
			<tr>
				<td><b>Full Name</b></td>
				<td><%out.print(user.getFirstname()+' '+user.getMiddlename()+' '+user.getLastname()); %></td>
				<td><b>Email</b></td>
				<td><%out.print(user.getEmail()); %></td>
				
			</tr>
			<tr>
				<td><b>Title</b></td>
				<td><%out.print(user.getTitle()); %></td>
				<td><b>Tel</b></td>
				<td><%out.print(user.getTel()); %></td>
			</tr>
			<tr>
				<td><b>Affiliation</b></td>
				<td><%out.print(user.getAffiliation()); %></td>
				<td><b>Fax</b></td>
				<td><%out.print(user.getFax()); %></td>
			</tr>
			</table>
			<br>
			</div>
			<p style="text-align:left">Assigned Papers</p>	
			<div id="assigned_paper" class="border">
			<table align="center" border="0" style="width:600px;text-align:center">
			<tr>
				<th>ID</th>
				<th>Topic</th>
				<th>Title</th>
				<th>Author(s)</th>
				<th>Assign Date</th>
				<th>&nbsp;</th>
			</tr>
			<%
				//HashMap<Integer,Paper> hm2 = impl.select_paper_assign1(member_id);
				int page_count = 1;
				int row = 1;
				int sum_page = 1;
				int sum_row = impl.get_paper_assign1_num(user.getLoginname());
				
				try{
					page_count = Integer.parseInt(request.getParameter("page"));
					sum_row = Integer.parseInt(request.getParameter("sum_row"));
//					System.out.println(page_count+" "+sum_row);
				}catch(Exception e){}
				
				HashMap<String,List<Paper>> map = impl.get_paper_assign1(member_id,page_count,row);
				//Set<Integer> set = hm2.keySet();
				List<Paper> list = map.get("all");
				Iterator it = list.iterator();
				//while(it.hasNext()){
				//	Integer i = (Integer)it.next();
				if(list.size()<1){
			 %>
			 <tr>
			 	<td colspan="6">
			 	<p align="center">No Paper Assigned Information!</p>
			 	</td>
			 <tr>
			 <%
			 	}
			 	for(int i=0;i<list.size();i++){
			 		Paper paper = list.get(i);
			  %>
			 	<td>
			 	<%
			 		out.print(paper.getPaperid());
			 	 %>
			 	</td>
			 	<td>
			 	<%
			 		String topic1 = paper.getFirsttopic();
			 		String topic2 = paper.getSecondtopic();
			 		String topics = topic1 + '&' +topic2;
			 		out.print(topics);
			 	 %>
			 	</td>
			 	<td>
			 	<%
			 		out.print(paper.getPapertitle());
			 	 %>
			 	</td>
			 	<td>
			 	<%
			 		out.print(paper.getAuthorname());
			 	 %>
			 	</td>
			 	<td>
			 	<%
			 		Date date = impl.get_paper_assign1_date(paper.getPaperid());
			 		out.print(date);
			 	 %>
			 	</td>
			 	<td>
			 		<a href="">Cancel Assign</a>
			 	</td>
			 </tr>
			 <%
			 }
			  %>	
			</table>
			</div>
			<form action="paper_assign_detail.jsp?id=<%=member_id%>" method="post" name="spage">
			<table width="95%" border="0" align="center">
			<tr>
				<td>
				&nbsp;
				</td>
				<td>
				<%
					sum_page = (sum_row + row -1) / row;
					if(list.size()>=1){
				 %>
				 <div align="center">
				 <input type="button" value="First" onClick="openpage(1)"
				  <%=page_count==1 ? "disabled" : "" %>>
				 
				 <input type="button" value="Preivew" onClick="openpage(<%=page_count-1%>)"
				  <%=page_count==1? "disabled" : "" %>>
				 
				 <input type="button" value="Next" onClick="openpage(<%=page_count+1%>)"
				  <%=page_count==sum_page? "disabled" : "" %>>
				 
				 <input type="button" value="Last" onClick="openpage(<%=sum_page%>)"
				  <%=page_count==sum_page? "disabled" : "" %>>
				 
				 <input type="hidden" name="page" value="">&nbsp;
				 
				 <font color="red" size="3"><%=page_count%></font> /
				 <font color="red" size="3"><%=sum_page%></font>
				 
				 </div>
				 <%
				 }
				  %>
				</td>
			</tr>
			</table>
			</form>	
			
			<p style="text-align:left">Assign Papers</p>
			<div id="assign_paper" class="border">
				<form name="assign_paper" onsubmit="show()">
				<table align="center" border="0" style="width:600px;text-align:center">
			<tr>
				<th>&nbsp;</th>
				<th>ID</th>
				<th>Topic</th>
				<th>Title</th>
				<th>Author(s)</th>
				<th>&nbsp;</th>
			</tr>
			<%
				int a_page_count = 1;
				int a_row = 4;
				int a_sum_page = 1;
				int a_sum_row = impl.get_unassigned1_num();
				try{
					a_page_count = Integer.parseInt(request.getParameter("a_page"));
					a_sum_row = Integer.parseInt(request.getParameter("a_sum_row"));
					System.out.println(a_page_count+","+a_sum_row);
				}catch(Exception e){};
				HashMap<String,List<Paper>> a_map = new HashMap<String,List<Paper>>();
				a_map = impl.get_paper_unassign1(a_page_count,a_row);
				List<Paper> a_list = new ArrayList<Paper>();
				a_list = a_map.get("all");
				Iterator a_it = a_list.iterator();
				if(a_list.size()<1){
			 %>
			 <tr>
			 	<td colspan="6">
			 	<p align="center">No Paper To Assign!</p>
			 	</td>
			 </tr>
			 <%
			 }
			 	for(int j=0;j<a_list.size();j++){
			 		Paper a_paper = a_list.get(j);
			  %>
			  <tr>
			  	<td>
			  	<input type="checkbox" name="assignment" value="<%=a_paper.getPaperid()%>">
			  	</td>
			  	<td>
			  	<%
			  		out.print(a_paper.getPaperid());
			  	 %>	
			  	</td>
			  	<td>
			  	<%
			  		String a_topic1 = a_paper.getFirsttopic();
			 		String a_topic2 = a_paper.getSecondtopic();
			 		String a_topics = a_topic1 + '&' + a_topic2;
			 		out.print(a_topics);
			  	 %>
			  	</td>
			  	<td>
			  	<%
			  		out.print(a_paper.getPapertitle());
			  	 %>
			  	</td>
			  	<td>
			  	<%
			  		out.print(a_paper.getAuthorname());
			  	 %>
			  	</td>
			  	<td>
			  	<a href="../paper_assign1?paper_id=<%=a_paper.getPaperid() %>&member_id=<%=member_id %>" onclick="return check(<%=member_id %>)">Assign</a>
			  	</td>
			  </tr>
			  <%
			  }
			   %>	
			   <tr>
			   		<td colspan="6">
			   		<hr>
			   		</td>
			   </tr>
			  <tr>
			  	<td>
			  	<input type="checkbox" name="select_all" value="All" onclick="selectall()">All
			  	</td>	
			  	<td colspan="4">
			  	&nbsp;
			  	</td>	
			  	<td>
			  	<input type="button" value="Assign" onclick="check_all(<%=member_id %>)">
			  	</td>
			  </tr>
			   </table>
			   </form>
			</div>
			<form action="paper_assign_detail.jsp?id=<%=member_id%>" method="post" name="a_spage">
			<table width="95%" border="0" align="center">
			<tr>
				<td>
				&nbsp;
				</td>
				<td>
				<%
					a_sum_page = (a_sum_row + a_row -1) / a_row;
					if(a_list.size()>=1){
				 %>
				 <div align="center">
				 <input type="button" value="First" onClick="a_openpage(1)"
				  <%=a_page_count==1 ? "disabled" : "" %>>
				 
				 <input type="button" value="Preivew" onClick="a_openpage(<%=a_page_count-1%>)"
				  <%=a_page_count==1? "disabled" : "" %>>
				 
				 <input type="button" value="Next" onClick="a_openpage(<%=a_page_count+1%>)"
				  <%=a_page_count==a_sum_page? "disabled" : "" %>>
				 
				 <input type="button" value="Last" onClick="a_openpage(<%=a_sum_page%>)"
				  <%=a_page_count==a_sum_page? "disabled" : "" %>>
				 
				 <input type="hidden" name="a_page" value="">&nbsp;
				 
				 <font color="red" size="3"><%=a_page_count%></font> /
				 <font color="red" size="3"><%=a_sum_page%></font>
				 
				 </div>
				 <%
				 }
				  %>
				</td>
			</tr>
			</table>
			</form>	
		</div>
		</div>
		
		<div class="nav"></div>
			
		<div id="footer" class="footer_color border">
			<p align="center"><b>&copy;2010 LSMS-All Rights Reserved.</b></p>
			<p align="center"> <b>Powered by Shu.</b></p>
		</div>
	</div>
  </body>
</html>
